//
//  AddMoneyViewController.m
//  Edumap
//
//  Created by 辰领科技 on 16/7/22.
//  Copyright © 2016年 yuf. All rights reserved.
//

#import "AddMoneyViewController.h"
#import "PayTypeViewController.h"

@interface AddMoneyViewController ()
<UITextFieldDelegate>
@property (strong, nonatomic) IBOutlet UIView *navView;
@property (strong, nonatomic) IBOutlet UIScrollView *scroView;
@property (strong, nonatomic) IBOutlet UIButton *payButton;
@property (strong, nonatomic) IBOutlet UITextField *moneyTextField;

@end

@implementation AddMoneyViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    
    [self initViewLayout];
}

- (void)initViewLayout{
    [self adaptiveViewLayout:self.view];
    self.view.backgroundColor = [UIColor colorWithWhite:0.957 alpha:1.000];
    [self adaptiveViewLayout:self.scroView];
    _scroView.contentSize = flexibleSize(CGSizeMake(0, 505), NO);
    _payButton.layer.cornerRadius = 5*VerticalRatio();
    _moneyTextField.delegate = self;
    
    
}



- (IBAction)back:(id)sender {
    [self backBtn];
}

#pragma mark == 立即支付/生成充值订单
- (IBAction)payNow:(id)sender {
    [self hideKeyBoard];
    if (_moneyTextField.text.length==0) {
        [CWHUDTips showTips:@"请输入充值金额！"];
        return;
    }
    if ([_moneyTextField.text integerValue] < 0.1) {
        [CWHUDTips showTips:@"充值金额不能低于0.1元！"];
        return;
    }
    NSMutableDictionary  *dic=[NSMutableDictionary dictionary];
    [dic setObject:[Common getLoginInfo][@"userId"] forKey:@"museId"];
    [dic setObject:[Common getLoginInfo][@"userId"] forKey:@"msceMemberId"];
    [dic setObject:[Common getLoginInfo][Key_User_password] forKey:@"musePwd"];
    [dic setObject:[Common getLoginInfo][Key_User_onlineKey] forKey:@"museOnlineTag"];
    [dic setObject:_moneyTextField.text forKey:@"meorAmount"];
    
    self.shareApi.delegate=self;
    [self.shareApi  requestOperationWithDic:dic withPath:JY_saveMemberEpurseOrder withHttpType:@"POST" withTag:JY_JY_saveMemberEpurseOrder];

}


#pragma   mark---- GetADBanner Request Delegate

-(void)fetchDatabaseFinished:(NSMutableDictionary *)database withTag:(NSInteger)tag{
    if (tag==JY_JY_saveMemberEpurseOrder) {
        if (  [[database valueForKey:@"flag"] integerValue]!=1 ) {
            
            [[CWHUDTips sharedInstance]  showTips:[database valueForKey:@"msg"]  withStatus:1 dismissAfter:1.5];
            
        }else {
            UIStoryboard *secondStroyBoard=[UIStoryboard storyboardWithName:@"HomeTeachStoryboard" bundle:nil];
            PayTypeViewController *page = [secondStroyBoard instantiateViewControllerWithIdentifier:@"PayType"];
            page.payOrderPrice = [NSString stringWithFormat:@"%@",database[@"result"][@"meorAmount"]];
            page.payOrderName = @"教育地图";
            page.payId = [NSString stringWithFormat:@"%@",database[@"result"][@"meorId"]];
            page.payOrderNo = [NSString stringWithFormat:@"%@",database[@"result"][@"meorNo"]];
            page.payTypes = @"2";
            [[Common getNavigation]pushViewController:page];
        }
    }
    
}

-(void)fetchDatabaseFailed:(NSError *)error message:(NSString *)message{
}

@end
